package com.dcy.daily.common.dataSource.properties;

import com.alibaba.druid.pool.DruidDataSource;

import javax.sql.DataSource;

/**
 * 存储数据库的连接信息，因为每一个数据源有不同的连接信息，
 * 需要对DruidDataSource设置对应的数据库连接信息。
 *
 * @author duanchunyu
 * @version 1.0.0
 * @createTime 2021年05月31日 14:45:00
 */
public class DataSourceProperties {

    /**
     * 数据库连接url
     */
    private String url;
    /**
     * 数据库连接用户名
     */
    private String username;
    /**
     * 用户据连接密码
     */
    private String password;

    public DataSource setDruidDataSource(DataSource dataSource){
        try{
            if(dataSource instanceof DruidDataSource){
                DruidDataSource druidDataSource = (DruidDataSource) dataSource;
                DruidDataSource newDruidDataSource = (DruidDataSource) druidDataSource.clone();
                newDruidDataSource.setUrl(url);
                newDruidDataSource.setUsername(username);
                newDruidDataSource.setPassword(password);
                return newDruidDataSource;
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return dataSource;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}
